<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>往来账务</title>
		<link rel="stylesheet" href="../../layui/css/layui.css" />
		<link rel="stylesheet" href="../../css/public.css" />
	</head>
	<body>
		<div class="layuimini-container">
			<div class="layuimini-main">
				<div class="layui-tab">
					<ul class="layui-tab-title">
						<li class="layui-this">客户所有单据</li>
						<li>客户消费情况</li>
						<li>客户账务信息</li>
					</ul>
					<div class="layui-tab-content">
						<div class="layui-tab-item layui-show">
							<div>
								<fieldset class="table-search-fieldset">
									<legend>搜索信息</legend>
									<form class="layui-form" action="" id="searchCurrentDataTimeAndCusName">
										<div class="layui-form-item">
											<div class="layui-inline" style="margin-left: -22px;">
												<label class="layui-form-label">往来时间：</label>
												<div class="layui-input-inline">
													<input type="text" class="layui-input" id="documentsCustomerTestOne" placeholder="yyyy-MM-dd" name="documentsCustomerTestOne">
												</div>
											</div>
											<div class="layui-inline" style="margin-left: -89px;">
												<label class="layui-form-label">至</label>
												<div class="layui-input-inline">
													<input type="text" class="layui-input" id="documentsCustomerTestTwo" placeholder="yyyy-MM-dd" name="documentsCustomerTestTwo">
												</div>
											</div>
											<div class="layui-inline developAndContract" style="margin-left: -20px;">
												<button class="layui-btn layui-btn-primary demo1">
													<i class="layui-icon layui-icon-down layui-font-12 develop"></i>
													<i class="layui-icon layui-icon-up layui-font-12 contract" style="display: none;"></i>
												</button>
											</div>
											<div class="layui-inline">
												<label class="layui-form-label">客户名称</label>
												<div class="layui-input-inline">
													<input type="text" class="layui-input" autocomplete="off" id="selectTable" lay-filter="selectTable" />
												</div>
												<div style="display: none;" id="allDocumentsCustomerNameList">
													<button type="button" data-method="offset" data-type="auto" id="amendCustomerName" lay-event="amendCustomerName"
													 class="layui-btn layui-btn-normal layui-btn-sm">修改</button>
												</div>
											</div>
											<!--<div class="layui-inline">
												<button type="button" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn" id="searchCurrentInfo">
													<i class="layui-icon"></i>
													搜 索
												</button>
											</div>-->
                                            <div class="layui-inline">
                                                <button type="button" class="layui-btn layui-btn-primary"  lay-submit lay-filter="searchCurrentInfo" id="searchCurrentInfo"><i class="layui-icon"></i> 搜 索</button>
                                            </div>
										</div>
									</form>
								</fieldset>
							</div>

							<fieldset class="table-search-fieldset" style="margin-top: 20px;">
								<legend>往来账务列表</legend>
								<div>
									<div id="btnList" style="display: none;">
									<!--<button type="button" data-method="offset" data-type="auto" id="makeCollections" lay-event="makeCollections"
                                     class="layui-btn layui-btn-normal layui-btn-sm">&nbsp;&nbsp;&nbsp;收款&nbsp;&nbsp;&nbsp;</button>-->

									<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="wholeSingleReturn">整单退货</button>
									<button type="button" class="layui-btn layui-btn-normal layui-btn-sm documentFiltering ">
										单据过滤
									</button>
								</div>
									<div style="margin: 10px 10px 10px 0px">
										<div style="position: relative;">
											<table class="layui-hide" id="commodity" lay-filter="commodity"></table>
											<div style="width: 150px; height: 20px; padding-left: 6px; background-color: #D9DADA; position: absolute; top: 489px; left: 290.5px;" id="displayDiv">欠款金额：<span id="amountInArear"></span>元</div>
										</div>
									</div>
								</div>
								<div style="border: 1px solid #e6e6e6; width: 1222px;">
									<div style="margin-left: 20px; padding-top: 10px;">单据的详细信息：<span style="color: red;" id="documentDetailsBillNo"></span>
										&nbsp;&nbsp;&nbsp;<span style="color: red;" id="documentDetailsBillName" ></span></div>
									<div style="margin: 10px 10px 10px 0px">
										<div>
											<table class="layui-hide" id="detailedInformation"></table>
										</div>
									</div>
								</div>
							</fieldset>
						</div>
						<div class="layui-tab-item">
							<div>
								<fieldset class="table-search-fieldset">
									<legend>搜索信息</legend>
									<form class="layui-form" action="" id="searchConsumptionDataTimeAndCusName">
										<div class="layui-form-item">
											<div class="layui-inline" style="margin-left: -22px;">
												<label class="layui-form-label">查询时间：</label>
												<div class="layui-input-inline">
													<input type="text" class="layui-input" id="customerConsumptionTestOne" placeholder="yyyy-MM-dd">
												</div>
											</div>
											<div class="layui-inline" style="margin-left: -89px;">
												<label class="layui-form-label">至</label>
												<div class="layui-input-inline">
													<input type="text" class="layui-input" id="customerConsumptionTestTwo" placeholder="yyyy-MM-dd">
												</div>
											</div>
											<div class="layui-inline developAndContract" style="margin-left: -20px;">
												<button class="layui-btn layui-btn-primary demo2">
													<i class="layui-icon layui-icon-down layui-font-12 develop"></i>
													<i class="layui-icon layui-icon-up layui-font-12 contract" style="display: none;"></i>
												</button>
											</div>
											<div class="layui-inline">
												<label class="layui-form-label">客户名称</label>
												<div class="layui-input-inline">
													<input type="text" class="layui-input" autocomplete="off" id="customerConsumptionSelectTable" lay-filter="customerConsumptionSelectTable"  />
												</div>
												<div style="display: none;" id="customerConsumptionCustomerNameList">
													<button type="button" data-method="offset" data-type="auto" id="amendCustomerNameTwo" lay-event="amendCustomerNameTwo"
													 class="layui-btn layui-btn-normal layui-btn-sm">修改</button>
												</div>
											</div>
											<div class="layui-inline">
												<button type="button" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn" lay-filter="searchCurrentInfoTwo" id="searchCurrentInfoTwo">
													<i class="layui-icon"></i>
													搜 索
												</button>
											</div>
										</div>
									</form>

								</fieldset>
								<div style="border: 1px solid #e6e6e6; width: 1277px;">
									<div id="customerConsumptionList" style="display: none;">
									</div>
									<div style="margin: 10px 10px 10px 0px">
										<div style="margin-left: 23px; margin-top: 23px;">
											<table class="layui-hide" id="customerConsumption"></table>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="layui-tab-item">
							<div>
								<fieldset class="table-search-fieldset">
									<legend>搜索信息</legend>
									<form class="layui-form" action="" id="searchInformateDataTimeAndCusName">
										<div class="layui-form-item">
											<div class="layui-inline" style="margin-left: -22px;">
												<label class="layui-form-label">查询时间：</label>
												<div class="layui-input-inline">
													<input type="text" class="layui-input" id="customerAccountingTestOne" placeholder="yyyy-MM-dd">
												</div>
											</div>
											<div class="layui-inline" style="margin-left: -89px;">
												<label class="layui-form-label">至</label>
												<div class="layui-input-inline">
													<input type="text" class="layui-input" id="customerAccountingTestTwo" placeholder="yyyy-MM-dd">
												</div>
											</div>
											<div class="layui-inline developAndContract" style="margin-left: -20px;">
												<button class="layui-btn layui-btn-primary demo3">
													<i class="layui-icon layui-icon-down layui-font-12 develop"></i>
													<i class="layui-icon layui-icon-up layui-font-12 contract" style="display: none;"></i>
												</button>
											</div>
											<div class="layui-inline">
												<button type="button" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn" lay-filter="customerAccountingInformation" id="customerAccountingInformation">
													<i class="layui-icon"></i>
													搜 索
												</button>
											</div>
										</div>
									</form>
								</fieldset>
								<div style="border: 1px solid #e6e6e6; width: 1277px;">
									<div id="customerAccountingList" style="display: none;">
										<div>

										</div>
									</div>
									<div style="margin: 10px 10px 10px 0px">
										<div style="margin-left: 23px; margin-top: 23px;">
											<table class="layui-hide" id="customerAccounting"></table>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>

		<!-- 点击收款按钮 -->
		<!--<div id="makeCollectionsInsertNewCommodityInfo" style="display: none; padding: 20px;">
			<form class="layui-form">
				<div class="layui-form-item" style="margin-top: 20px;">
					<label class="layui-form-label">欠款金额:</label>
					<div class="layui-input-inline" style="width: 230px; color: red; line-height: 38px; ">
						<input type="text" name="amountInArearMoney" readonly  class="layui-input" style="border: 0px;" id="amountInArearMoney">
					</div>
					<label class="layui-form-label">单&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号:</label>
					<div class="layui-input-inline" style="width: 230px;">
						<div class="layui-input-inline" style="width: 230px; line-height: 38px; ">
							<input type="text" name="seats" readonly  class="layui-input" style="border: 0px;" id="seats">
						</div>
					</div>
				</div>
				<div class="layui-form-item" style="margin-top: 20px;">
					<label class="layui-form-label">付款金额:</label>
					<div class="layui-input-inline" style="width: 230px;">
						<input type="text" name="username" lay-verify="required" class="layui-input">
					</div>
					<label class="layui-form-label">付款日期:</label>
					<div class="layui-input-inline" style="width: 230px;">
						<input type="text" class="layui-input" id="dateOfPayment" placeholder="yyyy-MM-dd">
					</div>
				</div>
				<div class="layui-form-item" style="margin-top: 40px;">
					<label class="layui-form-label">付款方式:</label>
					<div class="layui-input-inline" style="width: 230px;">
						<div class="layui-input-inline" style="width: 230px;">
							<select name="modeOfPayment" lay-verify="required">
								<option value=""></option>
								<option value="010">微信</option>
								<option value="011">现金</option>
								<option value="012">支付宝</option>
								<option value="013">银行转账</option>
							</select>
						</div>
					</div>
					<label class="layui-form-label">经&nbsp;&nbsp;办&nbsp;人:</label>
					<div class="layui-input-inline" style="width: 230px;">
						<select name="operator" lay-verify="required">
							<option value=""></option>
							<option value="010">小张</option>
							<option value="021">小李</option>
							<option value="0571">小白</option>
							<option value="0561">小陈</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item" style="margin-top: 40px;">
					<label class="layui-form-label">附加说明:</label>
					<div class="layui-input-inline" style="width: 582px;">
						<input type="text" name="username" lay-verify="required" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item" style="margin-top: 50px; margin-left: 198px; margin-bottom: -10PX;">
					<button type="button" class="layui-btn layui-btn-normal" style="margin-left: 111px;">确 定</button>
				</div>
			</form>
		</div-->
		<!-- 点击客户名称的下拉列表 -->
		<div id="customerNameAlterInfo" style="display: none; padding: 20px;">
			<form class="layui-form">
				<div class="layui-form-item">
					<label class="layui-form-label">客户名称:</label>
					<div class="layui-input-inline" style="width: 230px;">
						<input type="text" name="custName" lay-verify="required" readonly="" autocomplete="off" class="layui-input"
						 placeholder="普通客户" id="custName">
					</div>
                    <label class="layui-form-label">客户类型:</label>
                    <div class="layui-input-inline" style="width: 230px;">
                        <div class="layui-input-inline" style="width: 230px;">
                            <select name="custTypeId" lay-verify="required" id="custTypeId">
                                <option value=""></option>
                                <option value="010">微信</option>
                                <option value="011">现金</option>
                                <option value="012">支付宝</option>
                                <option value="013">银行转账</option>
                            </select>
                        </div>
                    </div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别:</label>
					<div class="layui-input-inline" style="width: 230px;">
						<select name="custSex" lay-verify="required" id="custSex">
							<option value=""></option>
							<option value="010">男</option>
							<option value="011">女</option>
						</select>
					</div>
					<label class="layui-form-label">出生日期:</label>
					<div class="layui-input-inline" style="width: 230px;">
						<input type="text" class="layui-input" id="custDate" placeholder="yyyy-MM-dd" name="custDate">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">联&nbsp;&nbsp;系&nbsp;人:</label>
					<div class="layui-input-inline" style="width: 230px;">
						<input type="text" name="custmName" lay-verify="required" class="layui-input" id="custmName">
					</div>
					<label class="layui-form-label">联系电话:</label>
					<div class="layui-input-inline" style="width: 230px;">
						<input type="text" name="custPhone" lay-verify="required" class="layui-input" id="custPhone">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">联系地址:</label>
					<div class="layui-input-inline" style="width: 582px;">
						<input type="text" name="custAddress" lay-verify="required" class="layui-input" id="custAddress">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">卡&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号:</label>
					<div class="layui-input-inline" style="width: 582px;">
						<input type="text" name="custMenmber" lay-verify="required" readonly="" autocomplete="off" class="layui-input" id="custMenmber">
					</div>
				</div>
				<div style="color: red; margin-left: 40px; margin-bottom: 10px;">（请输入后台会员编号，或者输入新的卡号将自动创建一个会员）</div>
				<div class="layui-form-item">
					<label class="layui-form-label">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注:</label>
					<div class="layui-input-block" style="width: 582px;">
						<textarea name="custComment" placeholder="请输入内容" class="layui-textarea" id="custComment"></textarea>
					</div>
				</div>
				<div class="layui-form-item" style="text-align: center;">
					<button type="button" class="layui-btn layui-btn-normal">保 存</button>
				</div>
			</form>
		</div>

		<script src="../../layui/layui.js"></script>
		<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
		<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
		</script>
		<script>
			layui.use(['laydate', 'dropdown', 'table', 'jquery', 'form', 'tableSelect', 'layer'], function() {
				var laydate = layui.laydate;
				var dropdown = layui.dropdown;
				var table = layui.table;
				var $ = layui.jquery;
				var form = layui.form;
				var tableSelect = layui.tableSelect;
				var layer = layui.layer;

				//客户所有单据执行一个laydate实例 选择时间
				laydate.render({
					elem: '#documentsCustomerTestOne', //指定元素
					value: new Date()
				});
				laydate.render({
					elem: '#documentsCustomerTestTwo', //指定元素
					value: new Date()
				});

				//获取客户所有单据里的往来时间的前部分input框
				var documentsCustomerTestOne = $('#documentsCustomerTestOne');
				//获取客户所有单据里的往来时间的后部分input框
				var documentsCustomerTestTwo = $('#documentsCustomerTestTwo');
				//获取客户消费里的往来时间的前部分input框
				var customerConsumptionTestOne = $('#customerConsumptionTestOne');
				//获取客户消费里的往来时间的后部分input框
				var customerConsumptionTestTwo = $('#customerConsumptionTestTwo');
				//获取客户账务信息里的往来时间的前部分input框
				var customerAccountingTestOne = $('#customerAccountingTestOne');
				//获取客户账务信息里的往来时间的后部分input框
				var customerAccountingTestTwo = $('#customerAccountingTestTwo');

				//获取当前日期
				var time = new Date();
				var year = time.getFullYear();
				var moneth = (time.getMonth() + 1);
				var day = time.getDate();

				//今天
				if (moneth < 10) {
					if (day < 10) {
						var nowDate = year + '-0' + moneth + '-0' + day;
					} else {
						var nowDate = year + '-0' + moneth + '-' + day;
					}
				} else {
					if (day < 10) {
						var nowDate = year + '-' + moneth + '-0' + day;
					} else {
						var nowDate = year + '-' + moneth + '-' + day;
					}
				}
				//今天开始时间
				var nowStartDate = nowDate;

				if (moneth == 0) {
					moneth = 12;
					year = year - 1;
				}

				//昨天
				var lastOneDay = new Date(year, (moneth - 1), 0).getDate() - (1 - day);
				if (moneth < 10) {
					if (day < 1) {
						var lastOneDayStart = year + '-0' + (moneth - 1) + '-' + lastOneDay;
					} else if (day - 1 < 10) {
						var lastOneDayStart = year + '-0' + moneth + '-0' + (day - 1);
					} else if (day - 1 >= 10) {
						var lastOneDayStart = year + '-0' + moneth + '-' + (day - 1);
					}
				} else {
					if (day < 1) {
						var lastOneDayStart = year + '-' + (moneth - 1) + '-' + lastOneDay;
					} else if (day - 1 < 10) {
						var lastOneDayStart = year + '-' + moneth + '-0' + (day - 1);
					} else if (day - 1 >= 10) {
						var lastOneDayStart = year + '-' + moneth + '-' + (day - 1);
					}
				}

				//前天
				var lastThreeDay = new Date(year, (moneth - 1), 0).getDate() - (2 - day);
				if (moneth < 10) {
					if (day < 2) {
						var lastTwoDayStart = year + '-0' + (moneth - 1) + '-' + lastThreeDay;
					} else if (day - 2 < 10) {
						var lastTwoDayStart = year + '-0' + moneth + '-0' + (day - 2);
					} else if (day - 2 >= 10) {
						var lastTwoDayStart = year + '-0' + moneth + '-' + (day - 2);
					}
				} else {
					if (day < 2) {
						var lastTwoDayStart = year + '-' + (moneth - 1) + '-' + lastThreeDay;
					} else if (day - 2 < 10) {
						var lastTwoDayStart = year + '-' + moneth + '-0' + (day - 2);
					} else if (day - 2 >= 10) {
						var lastTwoDayStart = year + '-' + moneth + '-' + (day - 2);
					}
				}

				//最近七天
				var lastServenDay = new Date(year, (moneth - 1), 0).getDate() - (7 - day);
				if (moneth < 10) {
					if (day < 7) {
						var lastServenDayStart = year + '-0' + (moneth - 1) + '-' + lastServenDay;
					} else if (day - 7 < 10) {
						var lastServenDayStart = year + '-0' + moneth + '-0' + (day - 7);
					} else if (day - 7 >= 10) {
						var lastServenDayStart = year + '-0' + moneth + '-' + (day - 7);
					}
					if (day < 10) {
						var lastServenDayEnd = year + '-0' + moneth + '-0' + day;
					} else {
						var lastServenDayEnd = year + '-0' + moneth + '-' + day;
					}
				} else {
					if (day < 7) {
						var lastServenDayStart = year + '-' + (moneth - 1) + '-' + lastServenDay;
					} else if (day - 7 < 10) {
						var lastServenDayStart = year + '-' + moneth + '-0' + (day - 7);
					} else if (day - 7 >= 10) {
						var lastServenDayStart = year + '-' + moneth + '-' + (day - 7);
					}
					if (day < 10) {
						var lastServenDayEnd = year + '-' + moneth + '-0' + day;
					} else {
						var lastServenDayEnd = year + '-' + moneth + '-' + day;
					}
				}


                //获取最近一月最开的时间，最近一月最后一天时间（今天）
                var lastMonthDateStartDay = new Date(year, (moneth - 1), 0).getDate() - (30 - day);
                if (moneth < 10) {
                    if (day < 10) {
                        var lastMonthDateStart = year + '-0' + (moneth-1) + '-0' + lastMonthDateStartDay;
                        var lastMonthDateEnd = year + '-0' + moneth + '-0' + day;
                    } else {
                        if (day < 30) {
                            if(lastMonthDateStartDay<10){
                                var lastMonthDateStart = year + '-0' + (moneth - 1) + '-0' + lastMonthDateStartDay;
							}else{
                                var lastMonthDateStart = year + '-0' + (moneth - 1) + '-' + lastMonthDateStartDay;
							}
                        } else {
                            if(lastMonthDateStartDay<10){
                                var lastMonthDateStart = year + '-0' + moneth + '-0' + lastMonthDateStartDay;
							}else{
                                var lastMonthDateStart = year + '-0' + moneth + '-' + lastMonthDateStartDay;
							}
                        }
                        var lastMonthDateEnd = year + '-0' + moneth + '-' + day;
                    }
                } else {
                    if (day < 10) {
                        var lastMonthDateStart = year + '-' + (moneth-1) + '-0' + lastMonthDateStartDay;
                        var lastMonthDateEnd = year + '-' + moneth + '-0' + day;
                    } else {
                        if (day < 30) {
                            if(lastMonthDateStartDay<10){
                                var lastMonthDateStart = year + '-' + (moneth - 1) + '-0' + lastMonthDateStartDay;
                            }else{
                                var lastMonthDateStart = year + '-' + (moneth - 1) + '-' + lastMonthDateStartDay;
                            }
                        } else {
                            if(lastMonthDateStartDay<10){
                                var lastMonthDateStart = year + '-' + moneth + '-0' + lastMonthDateStartDay;
                            }else{
                                var lastMonthDateStart = year + '-' + moneth + '-' + lastMonthDateStartDay;
                            }
                        }
                        var lastMonthDateEnd = year + '-' + moneth + '-' + day;
                    }
                }


				//本月最开始的一天，本月现在这一天
				if (moneth < 10) {
					if (day < 10) {
						var thisMonthDateStart = year + '-0' + moneth + '-01';
						var thisMonthDateEnd = year + '-0' + moneth + '-0' + day;
					} else {
						var thisMonthDateStart = year + '-0' + moneth + '-01';
						var thisMonthDateEnd = year + '-0' + moneth + '-' + day;
					}
				} else {
					if (day < 10) {
						var thisMonthDateStart = year + '-' + moneth + '-01';
						var thisMonthDateEnd = year + '-' + moneth + '-0' + day;
					} else {
						var thisMonthDateStart = year + '-' + moneth + '-01';
						var thisMonthDateEnd = year + '-' + moneth + '-' + day;
					}
				}

				//上月最开始的时间,上月最后一天
				var myDate = new Date(year, (moneth - 1), 0);
				if (moneth < 10) {
					var precedingMonthStart = year + '-0' + (moneth - 1) + '-01';
					var precedingMonthEnd = year + '-0' + (moneth - 1) + '-' + myDate.getDate();
				} else {
					var precedingMonthStart = year + '-' + (moneth - 1) + '-01';
					var precedingMonthEnd = year + '-' + (moneth - 1) + '-' + myDate.getDate();
				}

				//所有时间最开始的那一天,所有时间最后一天
				var allTheTimeStart = "2000-01-01";
				var allTheTimeEnd = year + '-' + moneth + '-' + day;
				if (moneth < 10) {
					if (day < 10) {
						var allTheTimeEnd = year + '-0' + moneth + '-0' + day;
					} else {
						var allTheTimeEnd = year + '-0' + moneth + '-' + day;
					}
				} else {
					if (day < 10) {
						var allTheTimeEnd = year + '-' + moneth + '-0' + day;
					} else {
						var allTheTimeEnd = year + '-' + moneth + '-' + day;
					}
				}



				//做时间下拉选择
				var developAndContract1 = $('.developAndContract1');
				var develop1 = $('.develop1');
				var contract1 = $('.contract1');
				developAndContract1.click(function() {
					develop1.css('display', 'none');
					contract1.css('display', 'block');
				});
				dropdown.render({
					elem: '.demo1',
					data: [{
						title: '今天',
						id: 1
					}, {
						title: '昨天',
						id: 2
					}, {
						title: '前天',
						id: 3
					}, {
						type: '-',
					}, {
						title: '最近七天',
						id: 4
					}, {
						title: '最近一月',
						id: 5
					}, {
						type: '-',
					}, {
						title: '本月',
						id: 6
					}, {
						title: '上月',
						id: 7
					}, {
						title: '所有时间',
						id: 8
					}],
					click: function(obj) {
						develop1.css('display', 'block');
						contract1.css('display', 'none');
						switch (obj.title) {
							case "今天":
								//获取客户所有单据里的往来时间
								documentsCustomerTestOne.val(nowStartDate);
								documentsCustomerTestTwo.val(nowStartDate);
								break;
							case "昨天":
								//获取客户所有单据里的往来时间
								documentsCustomerTestOne.val(lastOneDayStart);
								documentsCustomerTestTwo.val(lastOneDayStart);
								break;
							case "前天":
								//获取客户所有单据里的往来时间
								documentsCustomerTestOne.val(lastTwoDayStart);
								documentsCustomerTestTwo.val(lastTwoDayStart);
								break;
							case "最近七天":
								//获取客户所有单据里的往来时间
								documentsCustomerTestOne.val(lastServenDayStart);
								documentsCustomerTestTwo.val(lastServenDayEnd);
								break;
							case "最近一月":
								//获取客户所有单据里的往来时间
								documentsCustomerTestOne.val(lastMonthDateStart);
								documentsCustomerTestTwo.val(lastMonthDateEnd);
								break;
							case "本月":
								//获取客户所有单据里的往来时间
								documentsCustomerTestOne.val(thisMonthDateStart);
								documentsCustomerTestTwo.val(thisMonthDateEnd);
								break;
							case "上月":
								//获取客户所有单据里的往来时间
								documentsCustomerTestOne.val(precedingMonthStart);
								documentsCustomerTestTwo.val(precedingMonthEnd);
								break;
							case "所有时间":
								//获取客户所有单据里的往来时间
								documentsCustomerTestOne.val(allTheTimeStart);
								documentsCustomerTestTwo.val(allTheTimeEnd);
								break;
						}
					}
				});

				//搜索框内的弹出时间下拉列表内的最早时间
                /*$.post("/searchMortgageData", function(data){
                    allTheTimeStart=getDate(data);
                });*/


                // 监听往来账务搜索操作
                $('#searchCurrentInfo').on('click', function () {
                    //alert($('#selectTable').val());
					var currentTimeStart=$('#documentsCustomerTestOne').val();
					var currentTimeEnd=$('#documentsCustomerTestTwo').val();
					var custName=$('#selectTable').val();
                    //执行搜索重载
                    table.reload('commodity', {
                        where:{
                            currentTimeStart:currentTimeStart,
                            currentTimeEnd:currentTimeEnd,
                            ccustName:custName
                        },
                        page: {
                            curr: 1
                        }
                    });
                    //重新渲染所有单据下表数据
                    table.reload('detailedInformation',{
                        url:'/showDetailsOfTheDocumentDatas',
                        where: {
                            orsalOrdId:''
                        }

                    });

                    //表单重置
                    $('#searchCurrentDataTimeAndCusName')[0].reset();

                    //往来账务搜索框日期重新赋值
                    laydate.render({
                        elem: '#documentsCustomerTestOne', //指定元素
                        value: new Date()
                    });
                    laydate.render({
                        elem: '#documentsCustomerTestTwo', //指定元素
                        value: new Date()
                    });

                    //为单据的详细信息表格顶部的单号和客户名称重新赋值
                    $('#documentDetailsBillNo').html('');
                    $('#documentDetailsBillName').html('');

                });


				//往来账务列表上部分表格
                showCurrentAccountingData();
                //设置一个实付款，应付款的总金额变量
                var salOrdReceivableCountMoney=0;
                var salOrdPaidInCountMoney=0;
				function showCurrentAccountingData() {
                    table.render({
                        elem: '#commodity'
                        ,url: '/showCurrentAccountingDatas'
                        ,
                        /* data: [], */
                        totalRow: true,
                        width: 1225,
						height:563,
                        toolbar: '#btnList',
                        cols: [
                            [{
                                type: 'radio',
                                fixed: 'left'
                            }, {
                                field: 'ccustName',
                                width: 150,
                                title: '客户名称',
                                unresize: true,
                                totalRowText: '单据合计：<span id="countDataLength"></span>',
                                align: 'center',
                                templet:function (obj) {
                                    return obj.ccustName;
                                }
                            }, {
                                field: 'ccustTypeName',
                                width: 86,
                                title: '客户类型',
                                align: 'center',
                                templet:function (obj) {
                                    return obj.ccustTypeName;
                                }
                            }, {
                                field: 'csalOrdDate',
                                width: 80,
                                title: '日期',
                                sort: true,
                                align: 'center',
                                templet:function (obj) {
                                    return getDate(obj.csalOrdDate);
                                }
                            }, {
                                field: 'csalOrdId',
                                width: 80,
                                title: '单号',
                                sort: true,
                                align: 'center'
                            }, {
                                field: 'synopsis',
                                width: 86,
                                title: '内容摘要',
                                align: 'center',
                                templet:function (obj) {
                                    var synopsis;
                                    if('XT'==obj.csalOrdId.substring(0,2)){
                                        synopsis='销售退货支出'
									}else if('XS'==obj.csalOrdId.substring(0,2)){
                                        synopsis='商品销售付款'
									}
                                    return synopsis;
                                }
                            }, {
                                field: 'csalOrdReceivable',
                                width: 101,
                                title: '应收金额',
                                totalRowText: '<span id="csalOrdReceivable"></span>',
                                sort: true,
                                align: 'center',
                                templet:function (obj) {
                                    if('XT'==obj.csalOrdId.substring(0,2)){
                                        salOrdReceivableCountMoney-=obj.csalOrdReceivable;
                                        return -obj.csalOrdReceivable;
                                    }else if('XS'==obj.csalOrdId.substring(0,2)){
                                        salOrdReceivableCountMoney+=obj.csalOrdReceivable;
                                        return obj.csalOrdReceivable;
                                    }
                                    /*salOrdReceivableCountMoney=+obj.csalOrdReceivable;
                                    return obj.csalOrdReceivable;*/
                                }
                            }, {
                                field: 'csalOrdPaidIn',
                                width: 101,
                                title: '实收金额',
                                totalRowText: '<span id="csalOrdPaidIn"></span>',
                                sort: true,
                                align: 'center',
                                templet:function (obj) {
                                    if('XT'==obj.csalOrdId.substring(0,2)){
                                        salOrdPaidInCountMoney-=obj.csalOrdPaidIn;
                                        return -obj.csalOrdPaidIn;
                                    }else if('XS'==obj.csalOrdId.substring(0,2)){
                                        salOrdPaidInCountMoney+=obj.csalOrdPaidIn;
                                        return obj.csalOrdPaidIn;
                                    }
                                    /*salOrdPaidInCountMoney=+obj.csalOrdPaidIn;
                                    return obj.csalOrdPaidIn;*/
                                }
                            }, {
                                field: 'coupon',
                                width: 101,
                                title: '优惠金额',
                                totalRow: true,
                                sort: true,
                                align: 'center',
                                templet:function (obj) {
                                    return 0;
                                }
                            }, {
                                field: 'cempName',
                                width: 80,
                                title: '经办人',
                                align: 'center',
                                templet:function (obj) {
                                    return obj.cempName;
                                }
                            }, {
                                field: 'cempName',
                                width: 80,
                                title: '操作员',
                                align: 'center',
                                templet:function (obj) {
                                    return obj.cempName;
                                }
                            }, {
                                field: 'ccustPhone',
                                width: 86,
                                title: '联系电话',
                                align: 'center',
                                templet:function (obj) {
                                    return obj.ccustPhone;
                                }
                            }, {
                                field: 'ccustAddress ',
                                width: 86,
                                title: '联系地址',
                                align: 'center',
                                templet:function (obj) {
                                    if(null==obj.ccustAddress){
                                        return "";
									}
                                    return obj.ccustAddress;
                                }
                            }, {
                                field: 'csalOrdComment',
                                width: 80,
                                title: '备注',
                                align: 'center',
                                templet:function (obj) {
                                    return obj.csalOrdComment;
                                }
                            }, {
                                field: 'right',
                                width: 70,
                                toolbar: '#barDemo',
                                title: '操作',
                                fixed: 'right'
                            }]
                        ],
                        page: true,
                        limits: [10, 15, 20, 25, 50, 100],
                        limit: 15,
                        done: function(obj) {
                            //为应收金额，实收金额赋值
                            $('#csalOrdReceivable').html(salOrdReceivableCountMoney);
                            $('#csalOrdPaidIn').html(salOrdPaidInCountMoney);
                            //计算并赋值给欠款金额
							$('#amountInArear').html(salOrdReceivableCountMoney-salOrdPaidInCountMoney);
                            salOrdReceivableCountMoney=0;
                            salOrdPaidInCountMoney=0;
                            //判断如果往来账务没有数据则把欠款金额的div给隐藏，如果有数据则显示出来
                            if(0==obj.data.length){
                                $('#displayDiv').css('display', 'none');
                            }else{
                                $('#displayDiv').css('display', 'block');
                            }
                            //赋予往来账务单据合计条数
                            $('#countDataLength').html(obj.data.length);
							//默认选中第一条
                            $('.layui-table-view[lay-id=commodity] .layui-table-body tr[data-index=0] .layui-form-radio').click();

                            //单据过滤
                            dropdown.render({
                                elem: '.documentFiltering',
                                data: [{
                                    title: '所有单据',
                                }, {
                                    title: '销售单',
                                    id: 'XS'
                                }, {
                                    title: '退货单',
                                    id: 'XT'
                                }],
                                click: function(obj) {
                                    table.reload('commodity',{
                                        where:{
                                            saleOrderId:obj.id
										}
									});
                                    table.reload('detailedInformation',{
                                        url: '',
										data:[]
									});

                                }
                            });
                        }
                    });

                    //获取到往来账务上部分表格的单选选中数据
                    table.on('radio(commodity)' , function (obj) {
                        //为点击收款按钮后出现的弹窗中的欠款金额和客户名称赋值,单号
                        $('#seats').val(obj.data.csalOrdId);
                        $('#custmerNameName').html(obj.data.ccustName);
                        $('#amountInArearMoney').val(salOrdReceivableCountMoney-salOrdPaidInCountMoney);


                        //为单据的详细信息表格顶部的单号和客户名称赋值
						$('#documentDetailsBillNo').html(obj.data.csalOrdId);
                        $('#documentDetailsBillName').html(obj.data.ccustName);

                        table.reload('detailedInformation',{
                            url:'/showDetailsOfTheDocumentDatas',
							where: {
                                orsalOrdId:obj.data.csalOrdId
							}

                        });
                    });

                    table.on('row(commodity)' , function (obj) {
                        //obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
                        // obj.tr.find('i[class="layui-anim layui-icon"]').trigger("click");

                        /*obj.tr.addClass('layui-table-click').siblings().remove('layui-table-click');
                        obj.tr.find('input[lay-type="layTableRadio"]').prop("clicked",true);
                        var i=obj.tr.data('index');
                        var thisD=table.cache[commodity];
                        layui.each(thisD,function (s,item) {
                            if(i===s){
                                item.LAY_CHECKED=true;
                            }else{
                                delete item.LAY_CHECKED;
                            }
                        });*/
                        /*obj.tr.find('input[lay-type="layTableRadio"]').prop("clicked",true);
                        obj.tr.find('input[lay-type="layTableRadio"]').siblings().prop("clicked",false);*/
                    });
                    /*所选商品列表添加样式*/
                    /*table.on('row(commodity)', function(obj){
                        obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
                    });*/
				}

				function getDate(data) {
					var date = new Date(data);
					var m = date.getMonth() + 1 > 9 ? date.getMonth() + 1 : '0' + (date.getMonth() + 1);
                    var d = date.getDate() > 9 ? date.getDate() : '0' + date.getDate();
					return date.getFullYear() + '-' + m + '-' + d;
                }

                var tanchuchengIndex = -1;

                //整单退货按钮
                table.on('toolbar(commodity)', function(obj) {
                    var checkStatus = table.checkStatus(obj.config.id);

                    switch (obj.event){
						case "wholeSingleReturn":
                            //console.log(checkStatus.data[0].csalOrdId.substring(0,2));
							if("XT"==checkStatus.data[0].csalOrdId.substring(0,2)){
                                layer.msg("请选择单号以XS开头的数据！");
							}else if("XS"==checkStatus.data[0].csalOrdId.substring(0,2)){

                                $.post("/showDetailsOfTheDocumentDatas?orsalOrdId="+checkStatus.data[0].csalOrdId,function (data) {
                                    //console.log(JSON.stringify(JSON.parse(data).data));
                                    var billList = JSON.parse(data).data;

                                    var j = 0;

                                    var len = billList.length;

                                    for ( var i = 0 ; i < len; i++ ) {
                                        if ( billList[j].orsalRetDescProNum == 0 ) {
                                            billList.splice(j , 1);
                                        } else {
                                            j++;
										}
									}


                                    if (billList.length == 0){
                                        layer.alert("当前选择的单，没有可退货的商品！");
                                        return;
									}

									window.billList = JSON.stringify(billList);
                                    tanchuchengIndex = layer.open({
										type:2,
										title: '',
                                        content:"sell_customerReturn.html",
                                        area:['98%','98%'],
										success:function (obj) {
										    window.tanchuchengIndex = tanchuchengIndex;
                                        }
									});
                                });
							}
						    break;
					}
				});

				//收款按钮
				/*table.on('toolbar(commodity)', function(obj) {
					switch (obj.event) {
						case "makeCollections":
							layer.open({
								type: 1,
								title: '<h3 style="text-align: center;">客户名称：<span style="color: blue;" id="custmerNameName"></span><h3>',
								scrollbar: false, //屏蔽浏览器滚动条
								area: ['58%', '75%'],
								content: $('#makeCollectionsInsertNewCommodityInfo')
							});
							break;
					}
				});*/

				//操作内的删除按钮
                table.on('tool(commodity)', function (obj) {
                    if(obj.event ==='del'){
                        layer.confirm('真的要删除吗？', function (index) {
                            var csalOrdId=obj.data.csalOrdId;
                            table.reload('commodity',{
                                url:'/deleteSaleOrderInfo',
                                where: {
                                    csalOrdId:csalOrdId
                                }

                            });
                            layer.close(index);
                        });
                    }
                    //console.log(obj.event);
                });




				//收款弹窗内的付款日期
				laydate.render({
					elem: '#dateOfPayment', //指定元素
					value: new Date()
				});



				/*往来账务列表下部分详细单据信息表格*/
                showDetailsOfTheDocumentDatas();
				function showDetailsOfTheDocumentDatas() {

                    //声明变量计算保存总金额，数量
                    var countSaleOrderDescAllMoney=0;
                    var countSaleOrderDescProductNumber=0;

                    table.render({
                        elem: '#detailedInformation',/*
                        url: '/showDetailsOfTheDocumentDatas',*/
						data:[],
                        totalRow: true,
                        width: 1223,
                        cols: [
                            [{
                                type: 'radio',
                                fixed: 'left',
                            }, {
                                field: 'orproId ',
                                width: 112,
                                title: '商品编号',
                                align: 'center',
                                templet:function (obj) {
                                    return obj.orproId;
                                }
                            }, {
                                field: 'orproName',
                                width: 157,
                                title: '商品名称',
                                unresize: true,
                                totalRowText: '品种合计：<span id="countProductLength"></span>',
                                align: 'center',
                                templet:function (obj) {
                                    return obj.orproName;
                                }
                            }, {
                                field: 'orsalOrdDescUnit',
                                width: 112,
                                title: '单位',
                                align: 'center',
                                templet:function (obj) {
                                    return obj.orsalOrdDescUnit;
                                }
                            }, {
                                field: 'orsalOrdDescProPrice',
                                width: 112,
                                title: '单价',
                                sort: true,
                                align: 'center',
                                templet:function (obj) {
                                    return obj.orsalOrdDescProPrice;
                                }
                            }, {
                                field: 'orsalOrdDescProNum',
                                width: 112,
                                title: '数量',
                                totalRowText: "<span id='countSalDescNumber'></span>",
                                sort: true,
                                align: 'center',
                                templet:function (obj) {
                                    countSaleOrderDescProductNumber+=obj.orsalOrdDescProNum;
                                    return obj.orsalOrdDescProNum;
                                }
                            }, {
                                field: 'aggregateAmount ',
                                width: 112,
                                title: '总金额',
                                totalRowText: "<span id='countSalDescAllManey'></span>",
                                sort: true,
                                align: 'center',
                                templet:function (obj) {
                                    countSaleOrderDescAllMoney+=obj.orsalOrdDescProPrice*obj.orsalOrdDescProNum*1;
                                    return obj.orsalOrdDescProPrice*obj.orsalOrdDescProNum*1;
                                }
                            }, {
                                field: 'orproSize',
                                width: 112,
                                title: '产品规格',
                                align: 'center',
                                templet:function (obj) {
                                    return obj.orproSize;
                                }
                            }, {
                                field: 'orsalOrdDescProBatchNum',
                                width: 112,
                                title: '产品批号',
                                align: 'center',
                                templet:function (obj) {
                                    return obj.orsalOrdDescProBatchNum;
                                }
                            }, {
                                field: 'orsalOrdDescProValidityDate',
                                width: 112,
                                title: '有效期',
                                align: 'center',
                                templet:function (obj) {
                                    return getDate(obj.orsalOrdDescProValidityDate);
                                }
                            }, {
                                field: 'orsalOrdDescComment',
                                width: 112,
                                title: '备注',
                                align: 'center',
                                templet:function (obj) {
                                    if(null==obj.orsalOrdDescComment){
                                        return "";
									}
                                    return obj.orsalOrdDescComment;
                                }
                            }]
                        ],
                        page: true,
                        limits: [10, 15, 20, 25, 50, 100],
                        limit: 15,
                        done:function (obj) {
                            //为表下面的总金额以及数量赋值
                            $('#countSalDescNumber').html(countSaleOrderDescProductNumber);
                            $('#countSalDescAllManey').html(countSaleOrderDescAllMoney);
                            countSaleOrderDescAllMoney=0;
                            countSaleOrderDescProductNumber=0;
                            //商品明细表所有商品类型数量
                            $('#countProductLength').html(obj.data.length);
                            //默认选中第一条
                            $('.layui-table-view[lay-id=detailedInformation] .layui-table-body tr[data-index=0] .layui-form-radio').click();

                        }

                    });
                }



				//客户所有单据客户下拉表格
				tableSelect.render({
					elem: '#selectTable',
					checkedKey: 'id',
					id: "custom1",
					table: {
						url: '/showCustomerAllInfo',
						toolbar: '#allDocumentsCustomerNameList',
						cols: [
							[{
                                type: 'radio',
                                fixed: 'left'
                            },{
									field: 'custId',
									title: '编号',
									align: 'center'
								},
								{
									field: 'custName',
									title: '客户名称',
                                    align: 'center'
								},
								{
									field: 'custTypeName',
									title: '客户类型',
                                    align: 'center',
                                    templet:function (obj) {
                                        return obj.customerType.custTypeName;
                                    }
								},
								{
									field: 'custPhone',
									title: '联系电话',
                                    align: 'center'
								},
								{
									field: 'custAddress',
									title: '联系地址',
                                    align: 'center'
								}
							]
						]
					},
					done: function(elem, data) {
						var NEWJSON = []
						layui.each(data.data, function(index, item) {
							NEWJSON.push(item.custName)
						})
						elem.val(NEWJSON.join(","))
					}
				});

                //客户所有单据客户下拉表格内的修改按钮
                table.on('toolbar(custom1)', function(obj) {
                    //获选单选按钮选中情况
                    var checkStatus = table.checkStatus(obj.config.id);
                    //如果未选中，则弹出提示，如果选中则弹出修改客户弹窗
                    if(0>=checkStatus.data.length){
                        layer.msg("请选择数据！");
                    }else{
                        switch (obj.event) {
                            case "amendCustomerName":
                                layer.open({
                                    type: 1,
                                    title: '<h3 style="text-align: left;">修改客户商<h3>',
                                    scrollbar: false, //屏蔽浏览器滚动条
                                    area: ['58%', '75%'],
                                    content: $('#customerNameAlterInfo')
                                });
                                break;
                        }

                        //将数据传入修改客户弹窗内

                    }
                });



            //客户所有单据客户下拉列表内的修改弹窗内的出生日期
            laydate.render({
                elem: '#dateOfBirth', //指定元素
                value: new Date()
            });


            //客户消费情况据执行一个laydate实例 选择时间
            laydate.render({
                elem: '#customerConsumptionTestOne', //指定元素
                value: new Date()
            });
            laydate.render({
                elem: '#customerConsumptionTestTwo', //指定元素
                value: new Date()
            });

            //客户消费做时间下拉选择
            var developAndContract2 = $('.developAndContract2');
            var develop2 = $('.develop2');
            var contract2 = $('.contract2');
            developAndContract2.click(function() {
                develop2.css('display', 'none');
                contract2.css('display', 'block');
            });
            dropdown.render({
                elem: '.demo2',
                data: [{
                    title: '今天',
                    id: 1
                }, {
                    title: '昨天',
                    id: 2
                }, {
                    title: '前天',
                    id: 3
                }, {
                    type: '-',
                }, {
                    title: '最近七天',
                    id: 4
                }, {
                    title: '最近一月',
                    id: 5
                }, {
                    type: '-',
                }, {
                    title: '本月',
                    id: 6
                }, {
                    title: '上月',
                    id: 7
                }, {
                    title: '所有时间',
                    id: 8
                }],
                click: function(obj) {
                    develop2.css('display', 'block');
                    contract2.css('display', 'none');
                    switch (obj.title) {
                        case "今天":
                            //获取客户消费里的往来时间
                            customerConsumptionTestOne.val(nowStartDate);
                            customerConsumptionTestTwo.val(nowStartDate);
                            break;
                        case "昨天":
                            //获取客户消费里的往来时间
                            customerConsumptionTestOne.val(lastOneDayStart);
                            customerConsumptionTestTwo.val(lastOneDayStart);
                            break;
                        case "前天":
                            //获取客户消费里的往来时间
                            customerConsumptionTestOne.val(lastTwoDayStart);
                            customerConsumptionTestTwo.val(lastTwoDayStart);
                            break;
                        case "最近七天":
                            //获取客户消费里的往来时间
                            customerConsumptionTestOne.val(lastServenDayStart);
                            customerConsumptionTestTwo.val(lastServenDayEnd);
                            break;
                        case "最近一月":
                            //获取客户消费里的往来时间
                            customerConsumptionTestOne.val(lastMonthDateStart);
                            customerConsumptionTestTwo.val(lastMonthDateEnd);
                            break;
                        case "本月":
                            //获取客户消费里的往来时间
                            customerConsumptionTestOne.val(thisMonthDateStart);
                            customerConsumptionTestTwo.val(thisMonthDateEnd);
                            break;
                        case "上月":
                            //获取客户消费里的往来时间
                            customerConsumptionTestOne.val(precedingMonthStart);
                            customerConsumptionTestTwo.val(precedingMonthEnd);
                            break;
                        case "所有时间":
                            //获取客户消费里的往来时间
                            customerConsumptionTestOne.val(allTheTimeStart);
                            customerConsumptionTestTwo.val(allTheTimeEnd);
                            break;
                    }
                }
            });

            // 监听客户销售情况搜索操作
            $('#searchCurrentInfoTwo').on('click', function () {

                var currentTimeStartTwo=$('#customerConsumptionTestOne').val();
                var currentTimeEndTwo=$('#customerConsumptionTestTwo').val();
                var custNameTwo=$('#customerConsumptionSelectTable').val();
                //alert(custNameTwo);
                 //执行搜索重载
                table.reload('customerConsumption', {
                    where:{
                        currentTimeStart:currentTimeStartTwo,
                        currentTimeEnd:currentTimeEndTwo,
                        custName:custNameTwo
                    },
                    page: {
                        curr: 1
                    }
                });

                //表单重置
                $('#searchConsumptionDataTimeAndCusName')[0].reset();

                //客户消费情况为搜索框内的时间重新赋值
                laydate.render({
                    elem: '#customerConsumptionTestOne', //指定元素
                    value: new Date()
                });
                laydate.render({
                    elem: '#customerConsumptionTestTwo', //指定元素
                    value: new Date()
                });

			});

            //客户消费情况的数据表格
			//声明变量保存销售数量以及销售总金额的值
			var countSalCountNum=0;
			var countSalesTotaleAmount=0;
            table.render({
                elem: '#customerConsumption'
                    // ,url: '../../demo/table/user/-page=1&limit=20.js'
                    ,
                /* data: [], */
					url: '/showCustomerConsumptionDatas',
					totalRow: true,
					width: 1220,
					toolbar: '#customerConsumptionList',
					cols: [
						[{
							field: 'productId ',
							width: 131,
							title: '商品编号',
							align: 'center',
							sort: true,
                            templet:function (obj) {
                                return obj.productId;
                            }
						}, {
							field: 'salOrdDescProName',
							width: 150,
							title: '商品名称',
							unresize: true,
							totalRowText: '品种合计：<span id="saleTypeCount"></span>',
							align: 'center'
						}, {
							field: 'salOrdDescUnit',
							width: 131,
							title: '单位',
							align: 'center'
						}, {
							field: 'salOrdDescProNum',
							width: 131,
							title: '销售数量',
                            totalRowText: "<span id='salCountNum'></span>",
							sort: true,
							align: 'center',
							templet:function (obj) {
								countSalCountNum+=obj.countNum;
                                return obj.countNum;
                            }
						}, {
							field: 'totalSalesAmount',
							width: 121,
							title: '销售总金额',
                            totalRowText: "<span id='salesTotaleAmount'></span>",
							align: 'center',
							sort: true,
							templet:function (obj) {
                                countSalesTotaleAmount+=obj.salOrdDescProNum*obj.salOrdDescProPrice;
								return obj.salOrdDescProNum*obj.salOrdDescProPrice;
                            }
						}, {
							field: 'inveDescInventoryNum',
							width: 121,
							title: '库存数量',
							sort: true,
							align: 'center',
							templet:function (obj) {
							    /*if (null != obj) {
							        return;
								}
                                return obj.inventoryDesc.inveDescInventoryNum;*/
                                if(null==obj.inventoryDesc.inveDescInventoryNum){
                                    return 0;
                                }else{
                                    return obj.inventoryDesc.inveDescInventoryNum;
                                }
                            }
						}, {
							field: 'inveDescSize',
							width: 131,
							title: '产品规格',
							align: 'center',
                            templet:function (obj) {
                                /*if (null != obj) {
                                    return;
                                }*/
                                if(null==obj.inventoryDesc.inveDescSize){
                                    return 0;
								}else{
                                    return obj.inventoryDesc.inveDescSize;
								}

                            }
						}, {
							field: 'salOrdDescManufacturer',
							width: 131,
							title: '生产厂商',
							align: 'center'
						}, {
							field: 'salOrdDescComment',
							width: 161,
							title: '备注',
							align: 'center'
						}]
					],
					page: true,
					limits: [10, 15, 20, 25, 50, 100],
					limit: 15,
                    done:function (obj) {
					    //为客户消费表格底部的销售数量，销售总金额以及商品类型赋值
					    $('#salCountNum').html(countSalCountNum);
					    $('#salesTotaleAmount').html(countSalesTotaleAmount);
					    $('#saleTypeCount').html(obj.data.length);
                        countSalCountNum=0;
                        countSalesTotaleAmount=0;
                    }
				});


				//客户消费情况的 客户下拉表格
				tableSelect.render({
					elem: '#customerConsumptionSelectTable',
					checkedKey: 'id',
					id: "custom2",
					table: {
						/* data: [], */
						url:  '/showCustomerAllInfo',
						toolbar: '#customerConsumptionCustomerNameList',
						cols: [
                            [{
                                type: 'radio',
                                fixed: 'left'
                            },{
                                field: 'custId',
                                title: '编号',
                                align: 'center'
                            },{
                                field: 'custName',
                                title: '客户名称',
                                align: 'center'
                            },{
                                field: 'custTypeName',
                                title: '客户类型',
                                align: 'center',
                                templet:function (obj) {
                                    return obj.customerType.custTypeName;
                                }
                            },{
                                field: 'custPhone',
                                title: '联系电话',
                                align: 'center'
                            },{
                                field: 'custAddress',
                                title: '联系地址',
                                align: 'center'
                            }
                            ]
						]
					},
					done: function(elem, data) {
						var NEWJSON = []
						layui.each(data.data, function(index, item) {
							NEWJSON.push(item.custName)
						})
						elem.val(NEWJSON.join(","))
					}
				});



				//客户消费情况客户下拉表格内的修改按钮
				table.on('toolbar(custom2)', function(obj) {
                    //获选单选按钮选中情况
                    var checkStatusTwo = table.checkStatus(obj.config.id);
                    //如果未选中，则弹出提示，如果选中则弹出修改客户弹窗
                    if(0>=checkStatusTwo.data.length){
                        layer.msg("请选择数据！");
                    }else{
                        switch (obj.event) {
                            case "amendCustomerNameTwo":
                                layer.open({
                                    type: 1,
                                    title: '<h3 style="text-align: left;">修改客户商<h3>',
                                    scrollbar: false, //屏蔽浏览器滚动条
                                    area: ['58%', '75%'],
                                    content: $('#customerNameAlterInfo')
                                });
                                break;
                        }

                        //将数据传入修改客户弹窗内

                    }


				});

				//客户账务信息据执行一个laydate实例 选择时间
				laydate.render({
					elem: '#customerAccountingTestOne', //指定元素
					value: new Date()
				});
				laydate.render({
					elem: '#customerAccountingTestTwo', //指定元素
					value: new Date()
				});


				//客户账务信息做时间下拉选择
				var developAndContract3 = $('.developAndContract3');
				var develop3 = $('.develop3');
				var contract3 = $('.contract3');
				developAndContract3.click(function() {
					develop3.css('display', 'none');
					contract3.css('display', 'block');
				});
				dropdown.render({
					elem: '.demo3',
					data: [{
						title: '今天',
						id: 1
					}, {
						title: '昨天',
						id: 2
					}, {
						title: '前天',
						id: 3
					}, {
						type: '-',
					}, {
						title: '最近七天',
						id: 4
					}, {
						title: '最近一月',
						id: 5
					}, {
						type: '-',
					}, {
						title: '本月',
						id: 6
					}, {
						title: '上月',
						id: 7
					}, {
						title: '所有时间',
						id: 8
					}],
					click: function(obj) {
						develop3.css('display', 'block');
						contract3.css('display', 'none');
						switch (obj.title) {
							case "今天":
								//获取客户账务信息里的往来时间
								customerAccountingTestOne.val(nowStartDate);
								customerAccountingTestTwo.val(nowStartDate);
								break;
							case "昨天":
								//获取客户账务信息里的往来时间
								customerAccountingTestOne.val(lastOneDayStart);
								customerAccountingTestTwo.val(lastOneDayStart);
								break;
							case "前天":
								//获取客户账务信息里的往来时间
								customerAccountingTestOne.val(lastTwoDayStart);
								customerAccountingTestTwo.val(lastTwoDayStart);
								break;
							case "最近七天":
								//获取客户账务信息里的往来时间
								customerAccountingTestOne.val(lastServenDayStart);
								customerAccountingTestTwo.val(lastServenDayEnd);
								break;
							case "最近一月":
								//获取客户账务信息里的往来时间
								customerAccountingTestOne.val(lastMonthDateStart);
								customerAccountingTestTwo.val(lastMonthDateEnd);
								break;
							case "本月":
								//获取客户账务信息里的往来时间
								customerAccountingTestOne.val(thisMonthDateStart);
								customerAccountingTestTwo.val(thisMonthDateEnd);
								break;
							case "上月":
								//获取客户账务信息里的往来时间
								customerAccountingTestOne.val(precedingMonthStart);
								customerAccountingTestTwo.val(precedingMonthEnd);
								break;
							case "所有时间":
								//获取客户账务信息里的往来时间
								customerAccountingTestOne.val(allTheTimeStart);
								customerAccountingTestTwo.val(allTheTimeEnd);
								break;
						}
					}
				});

                // 监听客户账务信息搜索操作
                $('#customerAccountingInformation').on('click', function () {

                    var currentTimeStartThree=$('#customerAccountingTestOne').val();
                    var currentTimeEndThree=$('#customerAccountingTestTwo').val();
                    //执行搜索重载
                    table.reload('customerAccounting', {
                        where:{
                            currentTimeStart:currentTimeStartThree,
                            currentTimeEnd:currentTimeEndThree
                        },
                        page: {
                            curr: 1
                        }
                    });

                    //表单重置
                    $('#searchInformateDataTimeAndCusName')[0].reset();

                    //为客户账务信息搜索框内的时间重新赋值
                    laydate.render({
                        elem: '#customerAccountingTestOne', //指定元素
                        value: new Date()
                    });
                    laydate.render({
                        elem: '#customerAccountingTestTwo', //指定元素
                        value: new Date()
                    });

                });

				//客户账务信息的数据表格
				//设置变量保存合计金额以及相差金额
				var amountInTotal=0;
                var differentialAmount=0;
				table.render({
					elem: '#customerAccounting'
						// ,url: '../../demo/table/user/-page=1&limit=20.js'
						,
					/* data: [], */
					url: '/showCustomerAccountInformateDatas',
					totalRow: true,
					width: 1220,
					toolbar: '#customerAccountingList',
					cols: [
						[{
								title: '',
								colspan: 1,
								colGroup: true
							},
							{
								title: '客户消费商品情况',
								colspan: 3,
								align: 'center'
							}, {
								title: '客户账务情况',
								colspan: 3,
								align: 'center'
							}
						],
						[{
							field: 'custName',
							width: 243,
							title: '客户名称',
							totalRowText: '客户数目：<span id="countSalesCustNameDataLength"></span>',
							align: 'center',
							sort: true
						}, {
							field: 'salesOfGoods',
							width: 161,
							title: '商品销售额',
							totalRow: true,
							unresize: true,
							align: 'center',
                            templet:function (obj) {
                                if(null==obj.salesOfGoods){
									return 0;
                                }else{
                                    return obj.salesOfGoods;
								}
                            }
						}, {
							field: 'returnOfGoods',
							width: 161,
							title: '商品退货额',
							totalRow: true,
							align: 'center',
                            templet:function (obj) {
                                if(null==obj.returnOfGoods){
                                    return 0;
                                }else{
                                    return obj.returnOfGoods;
                                }
                            }
						}, {
							field: 'amountInTotal',
							width: 161,
							title: '合计金额',
                            totalRowText: '<span id="amountInTotalNum"></span>',
							sort: true,
							align: 'center',
							templet:function (obj) {
                                if(null==obj.salesOfGoods && null!=obj.returnOfGoods){
                                    amountInTotal+=(0-obj.returnOfGoods);
                                    return 0-obj.returnOfGoods;
                                }else if(null==obj.salesOfGoods && null==obj.returnOfGoods){
                                    amountInTotal+=0;
                                    return 0;
                                }else if(null!=obj.salesOfGoods && null==obj.returnOfGoods){
                                    amountInTotal+=(obj.salesOfGoods-0);
                                    return obj.salesOfGoods-0;
								}else{
                                    amountInTotal+=(obj.salesOfGoods-obj.returnOfGoods);
                                    return obj.salesOfGoods-obj.returnOfGoods;
								}
                            }
						}, {
							field: 'amountPayableByCustomer',
							width: 161,
							title: '客户应付金额',
							totalRow: true,
							align: 'center',
							sort: true,
                            templet:function (obj) {
                                if(null==obj.amountPayableByCustomer){
                                    return 0;
                                }else{
                                    return obj.amountPayableByCustomer;
                                }
                            }
						}, {
							field: 'customerPaidAmount',
							width: 161,
							title: '客户实付金额',
							totalRow: true,
							sort: true,
							align: 'center',
                            templet:function (obj) {
                                if(null==obj.customerPaidAmount){
                                    return 0;
                                }else{
                                    return obj.customerPaidAmount;
                                }
                            }
						}, {
							field: 'differentialAmount',
							width: 161,
							title: '相差金额',
                            totalRowText: '<span id="differentialAmountNum"></span>',
							align: 'center',
                            templet:function (obj) {
                                if(null==obj.amountPayableByCustomer && null!=obj.customerPaidAmount){
                                    differentialAmount+=(0-obj.customerPaidAmount);
                                    return Math.abs(0-obj.customerPaidAmount);
                                }else if(null==obj.amountPayableByCustomer && null==obj.customerPaidAmount){
                                    differentialAmount+=0;
                                    return 0;
                                }else if(null!=obj.amountPayableByCustomer && null==obj.customerPaidAmount){
                                    differentialAmount+=(obj.amountPayableByCustomer-0);
                                    return obj.amountPayableByCustomer-0;
                                }else{
                                    differentialAmount+=(obj.amountPayableByCustomer-obj.customerPaidAmount);
                                    return Math.abs(obj.amountPayableByCustomer-obj.customerPaidAmount);
                                }
                            }
						}]
					],
					page: true,
					limits: [10, 15, 20, 25, 50, 100],
					limit: 15,
					done: function (obj) {
					    //为客户数目，合计金额，以及相差金额赋值
					    $('#countSalesCustNameDataLength').html(obj.data.length);
					    $('#amountInTotalNum').html(amountInTotal);
                        $('#differentialAmountNum').html(Math.abs(differentialAmount));
                        amountInTotal=0;
                        differentialAmount=0;

                    }
				});

			});
		</script>
	</body>
</html>
